/*
package com.lx.chong.utils.messageutil;

import com.joriving.pdf.VO.PublicNumberTemplateVO;
import com.joriving.pdf.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * @author: whh
 * @date: 2018/10/10
 *//*

@Slf4j
public class WeChatUtilPdf {

    */
/**
     * @param appId 公众号/小程序的appid
     * @param secret 用户唯一凭证密钥
     * @return token
     * *//*

    public static String getToken(String appId,String secret){
        //获取accessTokenUrl的url链接
        String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + secret + "";
        return token(accessTokenUrl);
    }
    */
/**
     *
     * @param access_tokenurl
     * @return 获取access_tokenurl
     *//*

    public static JSONObject getToken(String access_tokenurl) {
        String result;
        String access_token = null;
        HttpGet request = new HttpGet(access_tokenurl);
        JSONObject jsonObject = null;
        // 获取当前客户端对象
        DefaultHttpClient httpClient = new DefaultHttpClient();
        // 通过请求对象获取响应对象
        try {
            HttpResponse response = httpClient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                jsonObject = JSONObject.fromObject(result);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    */
/**
     *
     * @param access_tokenurl
     * @return 获取access_tokenurl
     *//*

    public static String token(String access_tokenurl) {
        String result;
        String access_token = null;
        HttpGet request = new HttpGet(access_tokenurl);
        // 获取当前客户端对象
        DefaultHttpClient httpClient = new DefaultHttpClient();
        // 通过请求对象获取响应对象
        try {
            HttpResponse response = httpClient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                JSONObject jsonObject = JSONObject.fromObject(result);
                access_token = jsonObject.get("access_token").toString();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return access_token;
    }

    */
/**
     * @param access_token 调用接口凭证
     * @return 公众号的openid集合
     *//*

    public static List<String> getOpenId(String access_token) {
        //获取所有关注公众号的openid的url链接
        String userListUrl= "https://api.weixin.qq.com/cgi-bin/user/get?access_token="+access_token+"&next_openid=";
        String result;
        List<String> openIds = null;
        HttpGet request = new HttpGet(userListUrl);
        // 获取当前客户端对象
        DefaultHttpClient httpClient = new DefaultHttpClient();
        // 通过请求对象获取响应对象
        try {
            HttpResponse response = httpClient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                JSONObject jsonObject = JSONObject.fromObject(result);
                JSONObject objOpenIds = JSONObject.fromObject(jsonObject.get("data"));
                openIds = objOpenIds.getJSONArray("openid");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return openIds;
    }

    */
/**
     * @param token 调用接口凭证
     * @param openId 普通用户的标识，对当前公众号唯一
     * @return unionId
     * *//*

    public static JSONObject getUserInfo(String token,String openId)
    {
        String userInfoUrl="https://api.weixin.qq.com/cgi-bin/user/info?access_token="+token+"&openid="+openId+"&lang=zh_CN";
        String result;
        String unionId = null;
        HttpGet request = new HttpGet(userInfoUrl);
        // 获取当前客户端对象
        DefaultHttpClient httpClient = new DefaultHttpClient();
        // 通过请求对象获取响应对象
        try {
            HttpResponse response = httpClient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                return JSONObject.fromObject(result);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    */
/**
     * 登录凭证校验，通过 wx.login() 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程
     * @param appId 小程序Id
     * @param secret 用户唯一凭证密钥
     * @param js_code 登录时获取的
     * *//*

    public static JSONObject code2Session(String appId,String secret,String js_code)
    {
        try {
            String urlNameString = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appId + "&secret=" + secret
                    + "&js_code=" + js_code + "&grant_type=authorization_code";
            String result;
            // 根据地址获取请求,发送get请求
            HttpGet request = new HttpGet(urlNameString);
            // 获取当前客户端对象
            DefaultHttpClient httpClient = new DefaultHttpClient();
            // 通过请求对象获取响应对象
            HttpResponse response = httpClient.execute(request);
            // 判断网络连接状态码是否正常(0--200都数正常)
            if (response.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                return JSONObject.fromObject(result);
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    */
/**
     * 下行公众号推送公共方法
     * @param publicNumberTemplateVO
     * *//*

    public static JSONObject DownPushWeChatMessageTemplate(PublicNumberTemplateVO publicNumberTemplateVO)
    {
        Map<String,Object> map = new HashMap<>();
        //接收者openid
        map.put("touser", publicNumberTemplateVO.getOpenId());
        //模板ID
        map.put("template_id", publicNumberTemplateVO.getTempId());
        //模板跳转链接 待定
        map.put("url",publicNumberTemplateVO.getUrl());
        //region TODO 模板跳转链接
        Map<String,Object> miniProgram = new HashMap<>();
        //所需跳转到的小程序appid
        miniProgram.put("appid",publicNumberTemplateVO.getAppletsAppId());
        //所需跳转到小程序的具体页面路径，支持带参数,（示例index?foo=bar），暂不支持小游戏
        miniProgram.put("pagepath",publicNumberTemplateVO.getPagePath());
        //endregion
        map.put("miniprogram",miniProgram);
        //region TODO data模板数据参数
        Map<String,Object> data = new HashMap<>();
        Map<String,Object> first = new HashMap<>();
        first.put("value","有新订单啦");
        first.put("color","#173177");
        data.put("first",first);
        Map<String,Object> keyword1 = new HashMap<>();
        keyword1.put("value",publicNumberTemplateVO.getMaintenanceNum());
        keyword1.put("color","#173177");
        data.put("keyword1",keyword1);
        Map<String,Object> keyword2 = new HashMap<>();
        keyword2.put("value",DateUtil.getCurrentDateTime(3));
        data.put("keyword2",keyword2);
        Map<String,Object> keyword3 = new HashMap<>();
        keyword3.put("value",publicNumberTemplateVO.getTitle());
        data.put("keyword3",keyword3);
        Map<String,Object> keyword4 = new HashMap<>();
        keyword4.put("value",publicNumberTemplateVO.getContent());
        data.put("keyword4",keyword4);
        Map<String,Object> remark = new HashMap<>();
        remark.put("value",publicNumberTemplateVO.getRemark());
        data.put("remark",remark);
        //endregion
        map.put("data", data);
        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }

    */
/**
     * 上行公众号推送公共方法
     * @param publicNumberTemplateVO
     * *//*

    public static JSONObject UpPushWeChatMessageTemplate(PublicNumberTemplateVO publicNumberTemplateVO)
    {
        Map<String,Object> map = new HashMap<>();
        //接收者openid
        map.put("touser", publicNumberTemplateVO.getOpenId());
        //模板ID
        map.put("template_id", publicNumberTemplateVO.getTempId());
        //模板跳转链接 待定
        map.put("url",publicNumberTemplateVO.getUrl());
        //region TODO 模板跳转链接
        Map<String,Object> miniProgram = new HashMap<>();
        //所需跳转到的小程序appid
        miniProgram.put("appid",publicNumberTemplateVO.getAppletsAppId());
        //所需跳转到小程序的具体页面路径，支持带参数,（示例index?foo=bar），暂不支持小游戏
        miniProgram.put("pagepath",publicNumberTemplateVO.getPagePath());
        //endregion
        map.put("miniprogram",miniProgram);
        //region TODO data模板数据参数
        Map<String,Object> data = new HashMap<>();
        Map<String,Object> first = new HashMap<>();
        first.put("value","您有新的维修订单待处理");
        first.put("color","#173177");
        data.put("first",first);
        Map<String,Object> keyword1 = new HashMap<>();
        keyword1.put("value",publicNumberTemplateVO.getMaintenanceNum());
        data.put("keyword1",keyword1);
        Map<String,Object> keyword2 = new HashMap<>();
        keyword2.put("value",publicNumberTemplateVO.getTitle());
        data.put("keyword2",keyword2);
        Map<String,Object> keyword3 = new HashMap<>();
        keyword3.put("value",publicNumberTemplateVO.getGoodsCode());
        data.put("keyword3",keyword3);
        Map<String,Object> keyword4 = new HashMap<>();
        keyword4.put("value",publicNumberTemplateVO.getGoodsName());
        data.put("keyword4",keyword4);
        Map<String,Object> remark = new HashMap<>();
        remark.put("value",publicNumberTemplateVO.getRemark());
        data.put("remark",remark);
        //endregion
        map.put("data", data);
        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }

    */
/**
     * 将openId于unionId整合后返回，一次性取出openId对应的unionId，避免量大时遍历次数多导致效率低
     * *//*

    public static Map<String,Object> getUnionIdList(String token,List<String> openIds)
    {
        Map<String,Object> map = new HashMap<>();
        List<String> unionId = new ArrayList<>();
        List<String> openId = new ArrayList<>();
        List<String> nickName =new ArrayList<>();
        for(String item : openIds) {
            JSONObject userInfo = WeChatUtilPdf.getUserInfo(token, item);
            if (userInfo != null) {
                openId.add(item);
                //获取开放平台的唯一标识
                String unionIds = userInfo.get("unionid").toString();
                unionId.add(unionIds);
                String nickname=userInfo.get("nickname").toString();
                nickName.add(nickname);
            }
        }
        map.put("unionId",unionId);
        map.put("openId",openId);
        map.put("nickName",nickName);
        return map;
    }
}
*/
